package cn.edu.hubu.hubuhotel.controller;
import cn.edu.hubu.hubuhotel.entity.Reserve;
import cn.edu.hubu.hubuhotel.mapper.ReserveMapper;
import cn.edu.hubu.hubuhotel.mapper.RoomMapper;
import cn.edu.hubu.hubuhotel.service.ReserveService;
import cn.edu.hubu.hubuhotel.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
public class ReserveController {
    @Autowired
    private ReserveService reserveService;

    @Autowired
    private RoomMapper roomMapper;

    @RequestMapping("/reserve/login")
    public ResultVO login(String account, String password) {
        System.out.println("--------login");
        ResultVO vo = reserveService.loginByaccountandpwd(account,password);
        return vo;
    }

    @RequestMapping("/reserve/insert")
    public ResultVO insertReserve(Reserve reserve) {
        System.out.println("--------insertReserve");
        roomMapper.updateRoomState(reserve.getRoomId(),1);
        return reserveService.insertReserve(reserve);
    }

    @RequestMapping("/reserve/delete")
    public ResultVO deleteReserve(int userId, int roomId) {
        System.out.println("--------deleteReserve");
        roomMapper.updateRoomState(roomId,0);
        return reserveService.deleteReserve(userId,roomId);
    }

    @RequestMapping("/reserve/select")
    public ResultVO selectReserveByUserId(int userId) {
        System.out.println("--------selectReserveByUserId");
        return reserveService.selectByUserId(userId);
    }
}
